package com.tre.jdevtemplateboot.service.impl;

import com.tre.jdevtemplateboot.domain.po.SpEmployeeMst;
import com.tre.jdevtemplateboot.exception.business.SysInvalidUserException;
import com.tre.jdevtemplateboot.mapper.SpEmployeeMstMapper;
import com.tre.jdevtemplateboot.service.ISpEmployeeMstService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JDev
 * @since 2023-11-15
 */
@Service
public class SpEmployeeMstServiceImpl extends ServiceImpl<SpEmployeeMstMapper, SpEmployeeMst> implements ISpEmployeeMstService {

    @Autowired
    private SpEmployeeMstMapper spEmployeeMstMapper;

    @Override
    public SpEmployeeMst checkUserIdAndPassword(String userId, String password) {
        SpEmployeeMst employee = lambdaQuery()
                .eq(SpEmployeeMst::getAccount, userId)
                .eq(SpEmployeeMst::getPassword, password)
                .one();
        if (Objects.isNull(employee)) {//未查到此用户
            // TODO 抛出异常
            throw new SysInvalidUserException("账号或密码错误");
        }
        return employee;
    }
}
